home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * FILE I/O ROUTINES
-
- xref open_w,lineed,printf,read_in,prompt
- xref write_out,set_w,ask,cmd_w
- xdef readfile,writefile,filenm
-
- #edit.h
-
- *****************************************************************
- * Asks for a filename and reads it into current editing buffer
- * ENTRY: A5.L points to edit buffer window descriptor file
- * sets ed_err(a5) on error
- readfile:
- movem.l d1/d2/a0-a5,-(a7) Save caller's registers
- move.l #fprompt,a0 * setup prompt address
- move.l #filenm,a1 * setup input string address
- bsr ask * output prompt
- move.l #filenm,a0 * setup for file read
- move.l b_gap(a5),a2 * save current start of gap
- bsr read_in * try to read file
- move.l b_gap(a5),a3 * get new start of gap
- move.l a2,b_gap(a5) * save gap start point
-
- move.l a3,d1 * check how many chars read
- sub.l a2,d1 * d1 is now number of chars read
- move.l e_gap(a5),a2 * get end of gap address
- bra loop_test * this is a check-first loop
- loop_point:
- move.b -(a3),-(a2) * transfer chars to end of gap
- loop_test:
- dbra d1,loop_point
- move.l a2,e_gap(a5) * save new gap end address
- tst.w d0 * check if file was read
- beq exit * just leave if we read it
- cmp.b #1,d0 * is it file-not-found error?
- beq sk0_rf * yes, go tell user
- move.w #5,ed_err(a5) * was file-too-large error
- bra exit * print error
- sk0_rf:
- move.w #6,ed_err(a5) * new file message address
- exit:
- movem.l (a7)+,d1/d2/a0-a5 * restore caller's registers
- rts
- fprompt:
- dc.b 'Input Filename: ',0
- dc.w 0
- *****************************************************************
- * WRITEFILE - writes a block to disk
- * ENTRY: A1.L points to start of data buffer
- * D1.W holds number of bytes to write
- * EXIT: D0.W = 0 for success
- * = 1 for failure
- writefile:
- movem.l d1/d2/a0/a5,-(a7) * Save caller's registers
- move.l #cmd_w,a5 * get command I/O window desc.
- bsr open_w * open command window
- move.w w_ulcy(a5),-(a7) * setup prompt Y position
- move.w w_ulcx(a5),-(a7) * setup prompt X position
- move.l #wprompt,-(a7) * setup prompt address
- bsr printf * output prompt
- addq.l #8,a7 * fix the stack
- move.w w_ulcx(a5),d0 * input line X position
- add.w #17,d0 * new X position for input line
- move.w w_lrcx(a5),d2 * calculate max. line length for
- sub.w d0,d2 *... input line editor
- move.w d2,-(a7) * push max editing lines
- move.w d0,-(a7) * push starting screen column
- move.w w_ulcy(a5),-(a7) * push screen row
- move.l #filenm,-(a7) * push string address
- bsr lineed * get input line with filename
- add.l #10,a7 * pop lineed parameters
-
- move.l #filenm,a0 * setup for file write
- bsr write_out * try to read file
- tst.w d0 * check if file was written
- beq wexit * just leave if we wrote it
- move.w w_ulcy(a5),-(a7) * push message y position - 1
- addq.w #1,(a7) * adjust for correct position
- move.w w_ulcx(a5),-(a7) * push x position
- move.l #cant_rite,-(a7) * push message string address
- bsr printf * tell user
- addq.l #8,a7 * fix stack
- move.w #1,d0 * set error code
- wexit:
- movem.l (a7)+,d1/d2/a0/a5 * restore caller's registers
- rts
- wprompt:
- dc.b '%vOutput Filename: ',0
- cant_rite:
- dc.b '%v* * * Error writing file * * *',0
- dc.w 0
- *****************************************************************
- bss
- filenm: ds.b 80 * current filename buffer
-
- end